export CC

# => LWIP
ifndef MAKE_CLEAN
ifndef ENABLE_CUSTOM_LWIP
ENABLE_CUSTOM_LWIP		:= 2
else ifneq ($(ENABLE_CUSTOM_LWIP), 2)
$(error This library requires ENABLE_CUSTOM_LWIP=2)
endif
endif

COMPONENT_SUBMODULES := lwip

COMPONENT_INCDIRS := \
	. \
	src/Arch/$(SMING_ARCH)/include \
	lwip/src/include

COMPONENT_SRCDIRS := \
	src \
	src/Arch/$(SMING_ARCH)

COMPONENT_VARS		+= ENABLE_LWIPDEBUG
ENABLE_LWIPDEBUG	?= 0
LWIP_LIBNAME		:= clwip

LWIP_CMAKE_OPTIONS		:= \
	-G Ninja \
	-DLWIP_LIBNAME=$(LWIP_LIBNAME) \
	-DLWIP_DIR=$(COMPONENT_PATH)/lwip \
	-DCMAKE_MAKE_PROGRAM="$(NINJA)"

ifeq ($(ENABLE_LWIPDEBUG), 1)
LWIP_CMAKE_OPTIONS		+= -DCMAKE_BUILD_TYPE=Debug
else
LWIP_CMAKE_OPTIONS		+= -DCMAKE_BUILD_TYPE=Release
endif
ifeq ($(SMING_RELEASE),1)
	LWIP_CMAKE_OPTIONS	+= -DLWIP_NOASSERT=1
endif

LWIP_TARGET := $(COMPONENT_LIBDIR)/lib$(LWIP_LIBNAME).a
COMPONENT_TARGETS += $(LWIP_TARGET)
EXTRA_LIBS := $(LWIP_LIBNAME)

LWIP_ARCH_SRCDIR	:= $(COMPONENT_PATH)/src/Arch/$(SMING_ARCH)
include $(LWIP_ARCH_SRCDIR)/arch.mk

$(COMPONENT_RULE)$(LWIP_TARGET):
	$(Q) $(CMAKE) -DUSER_LIBDIR=$(COMPONENT_LIBDIR) $(LWIP_CMAKE_OPTIONS) $(LWIP_ARCH_SRCDIR)
	$(Q) $(NINJA)
